/**
 * Copyright:  Copyright (c) 2013
 *
 * @FileName		: DistributionRawMaterialAction.java
 * @PageName		: 원료재고
 * @Date			: 오후 1:33:58
 * @LastModifier	: 최경민
 * @LastModifyDate	: 
 * @LastModifier	: 
 * Change history	:
 */
package com.pulp.distribution.action;

import java.util.List;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.pulp.distribution.service.DistributionService;
import com.se.model.CommonSessionUser;

/**
 * @author 최경민
 * 
 */
public class DistributionRawMaterialAction extends ActionSupport {
	private static final long serialVersionUID = 4404069075956890168L;
	private String REQUEST_RESULT = "ok";
	static Logger logger = Logger.getLogger(DistributionRawMaterialAction.class);

	private String errorCode = "";

	private List rawMaterialYearList = null;
	private List rawMaterialMonthList = null;
	private List rawMaterialDateList = null;

	/**
	 * @return the rEQUEST_RESULT
	 */
	public String getREQUEST_RESULT() {
		return REQUEST_RESULT;
	}

	/**
	 * @param rEQUEST_RESULT the rEQUEST_RESULT to set
	 */
	public void setREQUEST_RESULT(String rEQUEST_RESULT) {
		REQUEST_RESULT = rEQUEST_RESULT;
	}

	/**
	 * @return the logger
	 */
	public static Logger getLogger() {
		return logger;
	}

	/**
	 * @param logger the logger to set
	 */
	public static void setLogger(Logger logger) {
		DistributionRawMaterialAction.logger = logger;
	}

	/**
	 * @return the errorCode
	 */
	public String getErrorCode() {
		return errorCode;
	}

	/**
	 * @param errorCode the errorCode to set
	 */
	public void setErrorCode(String errorCode) {
		this.errorCode = errorCode;
	}

	/**
	 * @return the rawMaterialYearList
	 */
	public List getRawMaterialYearList() {
		return rawMaterialYearList;
	}

	/**
	 * @param rawMaterialYearList the rawMaterialYearList to set
	 */
	public void setRawMaterialYearList(List rawMaterialYearList) {
		this.rawMaterialYearList = rawMaterialYearList;
	}

	/**
	 * @return the rawMaterialMonthList
	 */
	public List getRawMaterialMonthList() {
		return rawMaterialMonthList;
	}

	/**
	 * @param rawMaterialMonthList the rawMaterialMonthList to set
	 */
	public void setRawMaterialMonthList(List rawMaterialMonthList) {
		this.rawMaterialMonthList = rawMaterialMonthList;
	}

	/**
	 * @return the rawMaterialDateList
	 */
	public List getRawMaterialDateList() {
		return rawMaterialDateList;
	}

	/**
	 * @param rawMaterialDateList the rawMaterialDateList to set
	 */
	public void setRawMaterialDateList(List rawMaterialDateList) {
		this.rawMaterialDateList = rawMaterialDateList;
	}

	public String execute() throws Exception {
		System.out.println("DistributionRawMaterialAction==================");
		try {

			HttpServletRequest request = (HttpServletRequest) ServletActionContext.getRequest();
			ActionContext context = ActionContext.getContext();
			CommonSessionUser user = (CommonSessionUser) request.getSession().getAttribute(CommonSessionUser.ATTRIBUTE_NAME);
			ServletContext servletContext = ServletActionContext.getServletContext();
			WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(servletContext);
			DistributionService distributionService = (DistributionService) wac.getBean("distributionService");

			rawMaterialYearList = distributionService.getRawMaterialYear();
			rawMaterialMonthList = distributionService.getRawMaterialMonth();
			rawMaterialDateList = distributionService.getRawMaterialDate();

			request.setAttribute("rawMaterialYearList", rawMaterialYearList);
			request.setAttribute("rawMaterialMonthList", rawMaterialMonthList);
			request.setAttribute("rawMaterialDateList", rawMaterialDateList);

		} catch (Exception ex) {
			REQUEST_RESULT = "FAILED";
			ex.printStackTrace();
		}
		return REQUEST_RESULT;
	}
}
